package com.zzyl.nursing.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.service.IContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component("updateContractStatusJob")
public class UpdateContractStatusJob {

    @Autowired
    private IContractService contractService;

    public void  updateContractStatus() {
        LambdaUpdateWrapper<Contract> queryWrapper = new LambdaUpdateWrapper<>();
        queryWrapper.set(Contract::getStatus,1);
        queryWrapper.eq(Contract::getStatus,0);
        queryWrapper.gt(Contract::getEndDate, LocalDateTime.now());
        queryWrapper.lt(Contract::getStartDate, LocalDateTime.now());
        contractService.update(queryWrapper);


        LambdaUpdateWrapper<Contract> queryWrapper1 = new LambdaUpdateWrapper<>();
        queryWrapper1.set(Contract::getStatus,2);
        queryWrapper1.eq(Contract::getStatus,1);
        queryWrapper1.gt(Contract::getEndDate, LocalDateTime.now());
        contractService.update(queryWrapper1);

    }
}
